/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package br.com.janalise.util;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;

/**
 *
 * @author boskyn9
 */
public class StopWords {

    private static StopWords instance;
    private Locale lingua;
    private List<String> stopList;

    public List<String> getStopList() {
        return stopList;
    }

    public void setStopList(List<String> stopList) {
        this.stopList = stopList;
    }

    public Locale getLingua() {
        return lingua;
    }

    public void setLingua(Locale lingua) {
        this.lingua = lingua;
    }

    public static StopWords getInstance() throws IOException {
        if(instance==null)
            instance = new StopWords();
        instance.setStopList(getListStopWord(instance.getArquivo()));
        return instance;
    }

    public static StopWords getInstance(String sigla) throws IOException {
        if(instance==null)
            instance = new StopWords();
        instance.setLingua(new Locale(sigla));
        instance.setStopList(getListStopWord(instance.getArquivo()));
        return instance;
    }

    private static List<String> getListStopWord(String str){
        String list[] = str.split("\n");
        return Arrays.asList(list);
    }

    private String getArquivo() throws IOException{
        String arquivo=null;

        if(lingua==null)
            lingua = Locale.getDefault();

        if(lingua.toString().equalsIgnoreCase("pt_BR")){
           arquivo = Arquivo.lerArquivo("./config/stopwords/stopwordsPortugues.txt");
        }else if(lingua.toString().equalsIgnoreCase("es_ES")){
            arquivo = Arquivo.lerArquivo("./config/stopwords/stopwordsEspanhol.txt");
        }else if(lingua.toString().equalsIgnoreCase("en_US")){
            arquivo = Arquivo.lerArquivo("./config/stopwords/stopwordsIngles.txt");
        }

        
        return arquivo;
    } 
}
